package com.dlwx.firefighting.utils;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.utils.Debuger;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.dlwx.firefighting.R;
import com.dlwx.firefighting.listener.SampleListener;

/**
 * Created by Administrator on 2017/7/10.
 */

public class VideoPlayerUtils {

    public static void init(final Context context, final StandardGSYVideoPlayer videoPlayer, String url) {
//        url = "http://baobab.wdjcdn.com/14564977406580.mp4";
        ImageView imageView = new ImageView(context);
        imageView.setImageResource(R.mipmap.xxx2);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        //增加封面
        videoPlayer.setThumbImageView(imageView);


//设置播放url，第一个url，第二个开始缓存，第三个使用默认缓存路径，第四个设置title
        videoPlayer.setUp(url, true, null, "视频");
//非全屏下，不显示title
        videoPlayer.getTitleTextView().setVisibility(View.GONE);

//非全屏下不显示返回键
        videoPlayer.getBackButton().setVisibility(View.GONE);

//打开非全屏下触摸效果
//        detailPlayer.setIsTouchWiget(true);
        //设置全屏按键功能
        videoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                resolveFullBtn(videoPlayer,context);
            }
        });

//立即播放
//        videoPlayer.startPlayLogic();
        videoPlayer.setRotateViewAuto(false);
        videoPlayer.setLockLand(false);
//        videoPlayer.setPlayTag(TAG);
        videoPlayer.setShowFullAnimation(true);
        //循环
        //holder.videoPlayer.setLooping(true);
        videoPlayer.setNeedLockFull(true);

        //holder.videoPlayer.setSpeed(2);

        videoPlayer.setPlayPosition(0);
        videoPlayer.setStandardVideoAllCallBack(new SampleListener() {
            @Override
            public void onPrepared(String url, Object... objects) {
                super.onPrepared(url, objects);
                Debuger.printfLog("onPrepared");
                if (!videoPlayer.isIfCurrentIsFullscreen()) {
                    GSYVideoManager.instance().setNeedMute(true);
                }

            }

            @Override
            public void onQuitFullscreen(String url, Object... objects) {
                super.onQuitFullscreen(url, objects);
                GSYVideoManager.instance().setNeedMute(true);
            }

            @Override
            public void onEnterFullscreen(String url, Object... objects) {
                super.onEnterFullscreen(url, objects);
                GSYVideoManager.instance().setNeedMute(false);
            }
        });

    }

    /**
     * 全屏幕按键处理
     */
    private static void resolveFullBtn(final StandardGSYVideoPlayer standardGSYVideoPlayer, Context context) {
        standardGSYVideoPlayer.startWindowFullscreen(context, false, true);
//        isFullVideo = true;
    }



}
